import request from '@/utils/request.js';
import {download, toFormData, checkDownloadRes} from '@/utils/common.js';

/**
 * 分页查询就业统计-学生基础信息
 */
export async function pageInfos(params) {
  const res = await request.get('/admin/employment/statistic/student/baseInfo/list', {params});
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部就业统计-学生基础信息
 */
export async function listInfos(params) {
  const res = await request.get('/admin/employment/statistic/student/baseInfo/list', {params});
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询就业统计-学生基础信息
 */
export async function getInfo(id) {
  const res = await request.get('/admin/employment/statistic/student/baseInfo/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加就业统计-学生基础信息
 */
export async function addInfo(data) {
  const res = await request.post('/admin/employment/statistic/student/baseInfo', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改就业统计-学生基础信息
 */
export async function updateInfo(data) {
  const res = await request.put('/admin/employment/statistic/student/baseInfo', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除就业统计-学生基础信息
 */
export async function removeInfo(id) {
  const res = await request.delete('/admin/employment/statistic/student/baseInfo/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除就业统计-学生基础信息
 */
export async function removeInfos(ids) {
  const res = await request.delete('/admin/employment/statistic/student/baseInfo/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出就业统计-学生基础信息
 */
export async function exportInfos(params) {
  const res = await request({
    url: '/admin/employment/statistic/student/baseInfo/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `info_${Date.now()}.xlsx`);
}

/**
 * 查询毕业年份下拉列表
 * @returns {Promise<any>}
 */
export async function getGraduationYear() {
  const res = await request.get('/school/degree/graduationYear/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


export async function getCounsellors() {
  const res = await request.get('/school/counsellor/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//初始化年级，系别，专业
export async function initGrade() {
  const res = await request.get('/school/degree/init');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 获取校区列表
 * @returns {*}
 */
export async function getCampus() {
  const res = await request.get('/admin/school/dict/campus/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 获取年级列表
 * @returns {*}
 */
export async function getGrade() {
  const res = await request.get('/school/degree/grade/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 获取学籍状态
 * @returns {*}
 */
export async function getStudyStatus() {
  const res = await request.get('/admin/school/dict/studystate/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取系别列表
 * @returns {Promise<*>}
 */
export async function getDepartment() {
  const res = await request.get('/school/degree/department/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


//获取专业
export async function getMajor() {
  const res = await request.get('/school/degree/major/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


//获取性别列表
export async function getSex() {
  const res = await request.get('/admin/school/dict/sex/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//获取民族
export async function getNation() {
  const res = await request.get('/admin/school/dict/nation/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


//获取政治面貌
export async function getPolitical() {
  const res = await request.get('/admin/school/dict/political/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//困难类别
export async function getDifficulty() {
  const res = await request.get('/admin/school/dict/difficulty/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


//获取学制
export async function getStudyTime() {
  const res = await request.get('/admin/school/dict/studytime/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


export async function setDepartmentAndMajor(data) {
  const res = await request.put('/admin/employment/statistic/student/baseInfo/set/department/major', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 获取用户
 * @returns {Promise<any>}
 */
export async function getUser() {
  const res = await request.get('/admin/school/teacher/normal/selectlist');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 设置辅导员带兵
 */
export async function setLead(data) {
  const res = await request.put('/admin/employment/statistic/student/baseInfo/set/lead', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 导入学生数据
export async function importStudentInfo(data) {
  const res = await request.post('/admin/employment/statistic/student/baseInfo/importData', data, {timeout: 300000});
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//获取导入学生数据进度
export async function importStudentInfoProgress(data) {
  const res = await request.get('/admin/employment/statistic/student/baseInfo/importDataProgress/' + data);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 下载学生导入模板
 * @returns {Promise<void>}
 */
export async function downloadTemplate() {
  const res = await request({
    url: '/admin/employment/statistic/student/baseInfo/downloadTemplate',
    method: 'POST',
    responseType: 'blob'
  });
  download(res.data, `student_employment_base_template_${Date.now()}.xlsx`);
}


//获取所属组织
// export function getGroup() {
//   return request({
//     url: '/system/dict/data/group/selectlist',
//     method: 'get'
//   })
// }


//获取学籍状态组织
// export function getStudyState() {
//   return request({
//     url: '/system/dict/data/studystate/selectlist',
//     method: 'get'
//   })
// }


// export function getCurrentYear(){
//   return request({
//     url: '/system/school/current/year',
//     method: 'get'
//   })
// }
//







